import { Button, Form, Space, type FormInstance } from "antd";
import type { Store } from "antd/es/form/interface";

interface Props {
  form: FormInstance;
  initialValues?: Store;
  children?: React.ReactNode;
  onReset?: () => void;
  onSearch?: () => void;
}

/**
 * form 过滤组件
 * @param props
 * @returns
 */
export default function Filter(props: Props) {
  const _handler = {
    reset: () => {
      props.form.resetFields();
      props.onReset?.();
    },
    search: () => {
      props.onSearch?.();
    },
  };
  return (
    <Form
      className="rp-[.ant-form-item]:!mb-0 grid grid-cols-5 gap-4 rounded-xl bg-gray-100 !px-4 !py-2"
      form={props.form}
      initialValues={props.initialValues}
    >
      {props.children}
      <Form.Item className="col-[-1] justify-self-end">
        <Space>
          <Button type="primary" onClick={_handler.search}>
            搜索
          </Button>
          <Button onClick={_handler.reset}>重置</Button>
        </Space>
      </Form.Item>
    </Form>
  );
}
